const strFormat = require("../../util/strFormat");
const sql = (start, length) => {
  return strFormat(
    "select * from admin limit {start},{length};",
    { start: start, length: length }
  );
};

const getadmininfo = (connection, req, res) => {
  const start = parseInt(req.query.start) || 0;
  const length = parseInt(req.query.length) || 1000;

  connection.query(sql(start, length), (err, result) => {
    var data = null;

    if ( err ) {
      console.error(err);
      res.status(200).json({
        status: "fail",
        data: data,
      });
      return;
    } else {
      data = [];

      result.forEach(item => {
        data.push({
          id: item.id,
			    account: item.account,
        });
      });

      res.status(200).json({
        status: "success",
        data: data,
      });
    }
  });
}

module.exports = getadmininfo;